<?php
class Controller_DataCenter_Purchase extends Controller_Abstract
{
	function actionPurchaseHandleAnalysis()
	{
		$this->_view['title'] = '采购处理进度表';
		if ( ! empty($_GET['is_search']))
		{
			$url_arr = Helper_BSS_Normal::buildCondition();
			$result = OLM_Report::purchaseHandleAnalysis($url_arr);
			if ($result['ack'] == SUCCESS)
			{
				$this->_view['result'] = $result['result'];
				$this->_view['count'] = $result['count'];
			}
		}
	}
	
	function actionStockAnalysis()
	{
		$this->_viwe['title'] = '采购库存分析表';
		$purchase_categories = Product_Categories::getCategoriesTree();
		$this->_view['purchase_categories'] = json_encode($purchase_categories);
		$user = Purchase_Order::getUser();
		$this->_view['user'] = $user['data'];
		$this->_view['warehouse'] = Warehouse::getActiveWarehouse();
		$is_search = isset($_GET['is_search']) ? $_GET['is_search'] : '';
		if ($is_search)
		{
			$cp = isset($_GET['cp']) ? $_GET['cp'] : 0;
			$ps = isset($_GET['ps']) ? $_GET['ps'] : 30;
			$url_arr = Helper_BSS_Normal::buildCondition();
			$url_arr['limit'] = $user['ack'];
			$this->_view['url_arr_json'] = json_encode($url_arr);
			if (isset($url_arr['sort_by']) && isset($url_arr['sort_order']))
			{
				$order_by = $url_arr['sort_by'] . ' ' . $url_arr['sort_order'];
				$result = Product_Warehouse::search($url_arr, $cp, $ps, $order_by);
			}
			else
			{
				$result = Product_Warehouse::search($url_arr, $cp, $ps);
			}
			if ($result['ack'] == SUCCESS)
			{
				$page = new Helper_BSS_Page($result['pagination'], url('DataCenter::Purchase/StockAnalysis', $url_arr));
				$this->_view['page'] = $page->getPage();
				Helper_BSS_Normal::getProductImgUrl($result['data']);
				$sales_order_handle_status = array(
					Q::ini('custom_flag/sales_order_handle_status/new/value'),
					Q::ini('custom_flag/sales_order_handle_status/checkout/value'),
					Q::ini('custom_flag/sales_order_handle_status/sales_hold/value'),
					Q::ini('custom_flag/sales_order_handle_status/assigned/value'),
					Q::ini('custom_flag/sales_order_handle_status/printed/value'),
					Q::ini('custom_flag/sales_order_handle_status/printed_address/value'),
					Q::ini('custom_flag/sales_order_handle_status/weighed/value'),
					Q::ini('custom_flag/sales_order_handle_status/warehouse_hold/value')
				);
				$order_where = 'sales_order.warehouse_id=' . $url_arr['warehouse_id'] . ' and sales_order.handle_status in (' . implode(',', $sales_order_handle_status) . ') and sales_order.trash_status=' . Q::ini('custom_flag/sales_order_trash_status/normal/value');
				foreach ($result['data'] as $key => $p)
				{
					$detail = Sales_Order_Item::find($order_where . ' and sales_order_item.product_basic_id=?', $p['product_basic_id'])
						->joinLeft('sales_order', '', 'sales_order.id=sales_order_item.sales_order_id')
						->joinLeft('shop', '', 'shop.id=sales_order.shop_id')
						->setColumns('sales_order.number, sales_order.sales_time, sales_order_item.quantity, sales_order_item.id, shop.name')
						->asArray()->getAll();
					foreach ($detail as &$d)
					{
						$attr = Sales_Order_Item_Attribute::find('id=?', $d['id'])->asArray()->getAll();
						$d['attr'] = $attr;
					}
					unset($d);
					$result['data'][$key]['detail'] = $detail;
				}
				unset($url_arr['sort_by']);
				unset($url_arr['sort_order']);
				$this->_view['url'] = url('DataCenter::Purchase/StockAnalysis', $url_arr);
				$this->_view['product'] = $result['data'];
				if (isset($url_arr['pass_date']) && $url_arr['pass_date'])
				{
					$this->_view['dates'] = explode(',', $url_arr['pass_date']);
				}
			}
		}
	}
	
	function actionCustomizeDispalyStockAnalysis()
	{
		$this->_view['title'] = '自定义显示列';
		if (isset($_POST['fieldname']) && ($_POST['fieldname'] !== $_SESSION[Q::ini('custom_userdata_session_key')]['customize_purchase_stock_analysis']))
		{
			session_start();
			$_SESSION[Q::ini('custom_userdata_session_key')]['customize_purchase_stock_analysis'] = $_POST['fieldname'];
			QDB::getConn()->execute('update user set custom_session_data = \'' . json_encode($_SESSION[Q::ini('custom_userdata_session_key')], JSON_UNESCAPED_UNICODE) . '\' where id = ' . CURRENT_USER_ID);
			session_write_close();
		}
		return $this->_redirect($_SERVER['HTTP_REFERER']);
	}
	
	function actionStockAnalysisDownload()
	{
		$this->_view['title'] = '请求下载存货分析表';
		set_time_limit(300);
		$url_arr = json_decode($_REQUEST['url_arr_json'], true);
		if (isset($url_arr['is_search']))
		{
			$result = Product_Warehouse::search($url_arr, 0, 0);
			$data = '';
			foreach ($_SESSION[Q::ini('custom_userdata_session_key')]['customize_purchase_stock_analysis'] as $s)
			{
				$data .= "$s\t";
			}
			$data .= "\n";
			foreach ($result['data'] as $key => $r)
			{
				$r['purchase_status'] = Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $r['purchase_status'], 'name');
				$r['sales_status'] = Helper_BSS_Normal::getIniOne('product_sales_status', 'value', $r['sales_status'], 'name');
				$r['notes'] = str_replace(array("\n", "\r", "\r\n", "\t"), ' ', $r['notes']);
				$r['product_basic_name'] = str_replace(array("\n", "\r", "\r\n", "\t"), ' ', $r['product_basic_name']);
				$r['purchase_note'] = str_replace(array("\n", "\r", "\r\n", "\t"), ' ', $r['purchase_note']);
				foreach ($_SESSION[Q::ini('custom_userdata_session_key')]['customize_purchase_stock_analysis'] as $k => $v)
				{
					$data .= "{$r[$k]}\t";
				}
				$data .= "\n";
			}
			$data = iconv("UTF-8","UTF-16LE",$data);
			$data = "\xFF\xFE".$data;
			$file_name = 'inventory-purchase-' . date('YmdHis', CURRENT_TIMESTAMP) . '-' . CURRENT_USER_NAME . ".xls";
			$file = file_put_contents(Q::ini('custom_system/export_dir') . $file_name, $data);
			echo json_encode(array(
					'ack' => 'success',
					'url' => Q::ini('custom_system/export_url') . $file_name
			));
			exit;
		}
	}
	
	function actionUpdateProductPurchaseStatusSingle()
	{
		$this->_view['title'] = '更新单个产品采购状态';
		$temp = explode('_', $_REQUEST['data']);
		$product_warehouse_id = $temp[0];
		$purchase_status = $temp[1];
		Product_Warehouse::updatePurchaseStatus($product_warehouse_id, 0, 0, $purchase_status, CURRENT_USER_ID);
		$ret = array(
				'ack' => 'success',
				'status_html' => "<font color='#".Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $purchase_status, 'color')."'>".Helper_BSS_Normal::getIniOne('product_purchase_status', 'value', $purchase_status, 'name')."</font>"
		);
		echo json_encode($ret);
		exit;
	}
	
	function actionUpdateProductSalesStatusAllArtificial()
	{
		$this->_view['title'] = '更新产品状态';
		OLM_Cron::UpdateProductStatus();
	}
	
	function actionStatistics()
	{
		$this->_view['title'] = '采购统计表-按供应商';
		set_time_limit(0);
		$user = Purchase_Order::getUser();
		$this->_view['user'] = $user['data'];
		$is_search = isset($_GET['is_search']) ? $_GET['is_search'] : '';
		if ($is_search)
		{
			$where = '1';
			$url_arr = Helper_BSS_Normal::buildCondition();
			$provider = Product_Provider::search($url_arr, 0, 0);
			$result = array();
			if (empty($url_arr['begin_storage_audit_time']) || empty($url_arr['end_storage_audit_time']))
			{
				return $this->_redirectMessage('入库日期不能为空！', '请检查入库日期的搜索条件!', $_SERVER['HTTP_REFERER'], FAILURE);
			}
			foreach ($provider['data'] as $k => $p)
			{
				//本地仓采购入库
				$gz = QDB::getConn()->execute('select sum(inventory_log.cost_amount) as purchase_amount, sum(inventory_log.remaining_quantity*inventory_log.cost_price) as stock_amount from inventory_log left join ' . Q::ini('custom_flag/inventory_log_type/purchase/relate_table_name') . ' on ' . Q::ini('custom_flag/inventory_log_type/purchase/relate_table_name') . '.id=inventory_log.relate_table_id where inventory_log.time>=\'' . $url_arr['begin_storage_audit_time'] . '\' and inventory_log.time<=\'' . $url_arr['end_storage_audit_time'] . ' 23:59:59\' and inventory_log.type=' . Q::ini('custom_flag/inventory_log_type/purchase/value') . ' and ' . Q::ini('custom_flag/inventory_log_type/purchase/relate_table_name') . '.actual_provider_id=' . $p['id'])->fetchRow();
				$purchase_amount = $gz['purchase_amount'];
				$stock_amount = $gz['stock_amount'];
				if ($purchase_amount || $stock_amount)
				{
					$result[$k] = $p;
					$result[$k]['stock_amount'] = $stock_amount;	
					$result[$k]['purchase_amount'] = $purchase_amount;
					$result[$k]['categories'] = Product_Categories::find('provider_categories_mapping.product_provider_id=?', $p['id'])
						->joinLeft('provider_categories_mapping', '', 'provider_categories_mapping.product_categories_id=product_categories.id')
						->asArray()->getAll(); 
				}
			}
			$url_arr_json = array(
				'ajax_provider' => $url_arr['ajax_provider'] ? $url_arr['ajax_provider'] : '',
				'begin_storage_audit_time' => $url_arr['begin_storage_audit_time'],
				'end_storage_audit_time' => $url_arr['end_storage_audit_time']
			);
			$this->_view['result'] = $result;
			$this->_view['url_arr_json'] = json_encode($url_arr_json);
		}
	}
	
	function actionProviderDetail()
	{
		$this->_view['title'] = '供应商详情';
		$provider = Product_Provider::find('product_provider.id = ?', $_GET['id'])
			->joinLeft('user', 'name as follow_username', 'user.id=product_provider.follow_user_id')
			->asArray()->getOne();
		$provider['mapping'] = QDB::getConn()->execute('select product_categories_id from provider_categories_mapping where product_provider_id=' . $provider['id'])->fetchCol();
		$this->_view['categories'] = Product_Categories::getCategoriesTree();
		$this->_view['provider'] = $provider;
	}
	
	function actionStatisticsDownload()
	{
		$this->_view['title'] = '采购统计表-按供应商（下载）';
		set_time_limit(0);
		if (isset($_GET['url_arr']))
		{
			$url_arr = json_decode($_GET['url_arr'], true);
			if (!empty($url_arr['begin_storage_audit_time']) && !empty($url_arr['end_storage_audit_time']))
			{
				$where = Product_Provider::buildSearchWhere($url_arr);
				$provider = Product_Provider::find($where)->asArray()->getAll();
				include Q::ini('custom_system/lib_dir').'PHPExcel.php';
				$phpexcel = new PHPExcel();
				$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
				$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
				$phpexcel->getProperties()->setTitle("供应商采购入库统计报表");
				$phpexcel->getProperties()->setSubject("供应商采购入库统计报表");
				$phpexcel->getProperties()->setDescription("供应商采购入库统计报表-运营支撑系统");
				$phpexcel->getProperties()->setKeywords("供应商采购入库统计报表");
				$phpexcel->getProperties()->setCategory("供应商采购入库统计报表");
				$phpexcel->setActiveSheetIndex(0);
				$phpexcel->getActiveSheet()->setTitle("供应商采购入库统计报表");
				$phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
				$phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
				$phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);

				$phpexcel->getActiveSheet()->setCellValue('A1', "ID");
				$phpexcel->getActiveSheet()->setCellValue('B1', "供应商");
				$phpexcel->getActiveSheet()->setCellValue('C1', "总金额");
				$phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
				$i = 2;
				foreach ($provider as $p)
				{
					//本地仓采购入库
					$gz = QDB::getConn()->execute('select sum(inventory_log.cost_amount) from inventory_log left join ' . Q::ini('custom_flag/inventory_log_type/purchase/relate_table_name') . ' on ' . Q::ini('custom_flag/inventory_log_type/purchase/relate_table_name') . '.id=inventory_log.relate_table_id where inventory_log.time>=\'' . $url_arr['begin_storage_audit_time'] . '\' and inventory_log.time<=\'' . $url_arr['end_storage_audit_time'] . ' 23:59:59\' and inventory_log.type=' . Q::ini('custom_flag/inventory_log_type/purchase/value') . ' and ' . Q::ini('custom_flag/inventory_log_type/purchase/relate_table_name') . '.actual_provider_id=' . $p['id'])->fetchOne();
					$amount = $gz;
					if ($amount)
					{
						$phpexcel->getActiveSheet()->setCellValue('A'.$i, $p['id']);
						$phpexcel->getActiveSheet()->setCellValue('B'.$i, $p['name']);
						$phpexcel->getActiveSheet()->setCellValue('C'.$i, $amount);
						$i++;
					}
				}
				$objWriter = new PHPExcel_Writer_Excel5($phpexcel);
				header("Content-Type: application/vnd.ms-execl");
				header("Content-Type: application/octet-stream");
				header("Content-Type: application/download");
				header('Content-Disposition:inline;filename="' . date('Y.m.d', strtotime($url_arr['begin_storage_audit_time'])) . '-' . date('Y.m.d', strtotime($url_arr['end_storage_audit_time'])) . '采购入库报表.xls"');
				header("Content-Transfer-Encoding: binary");
				header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
				header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
				header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
				header("Pragma: no-cache");
				$objWriter->save('php://output');
				exit;
			}
		}
	}
	
	function actionProvider()
	{
		$this->_view['title'] = '供应商请求ajax';
		$q = $_REQUEST['q'];
		$provider = Product_Provider::find('id like ? or name like ?', $q.'%', '%'.$q.'%')->asArray()->getAll();
		$result = array();
		foreach ($provider as $p)
		{
			$result[] = array(
				0 => $p['id'] . ' ' . $p['name'],
				'id' => $p['id']
			);
		}
		echo json_encode($result);
		exit;
	}
	
	function actionPurchaseSummaryReport()
	{
		$this->_view['title'] = '采购汇总表';
		set_time_limit(0);
		$purchase_categories = Product_Categories::getCategoriesTree();
		$this->_view['purchase_categories'] = json_encode($purchase_categories);
		$warehouse = Warehouse::getActiveWarehouse();
		$this->_view['warehouse'] = $warehouse;
		$is_search = isset($_GET['is_search']) ? $_GET['is_search'] : '';
		if ($is_search)
		{
			$url_arr =Helper_BSS_Normal::buildCondition();
			if (!empty($_GET['product_categories_id']))
			{
				$where = 'product_categories.parent_id=' . $_GET['product_categories_id'];
			}
			else
			{
				$where = 'product_categories.parent_id=0';
			}
			$ret = array();
			$categories = Product_Categories::find($where)->asArray()->getAll();
			if (!$categories)
			{
				$categories = Product_Categories::find('product_categories.id=?', $_GET['product_categories_id'])->asArray()->getAll();
			}
			foreach ($categories as $c)
			{
				$product_arr = array();
				$offspring_categories = Product_Categories::getOffspringById($c['id']);
				if ($offspring_categories)
				{
					$products = Product_Basic::find('product_categories_id in (?)', $offspring_categories)->asArray()->getAll();
				}
				else
				{
					$products = Product_Basic::find('product_categories_id=?', $c['id'])->asArray()->getAll();
				}
				foreach ($products as $product)
				{
					$product_warehouse = Product_warehouse::find('product_basic_id=? and warehouse_id in(?) and sold_quantity>actual_quantity', $product['id'], $url_arr['warehouse_id']?$url_arr['warehouse_id']:$_GET['warehouse_id'])->asArray()->getOne(); 
					if ($product_warehouse)
					{
						$product_arr[$product_warehouse['product_basic_id']] = array(
							'name' => $product['name'],
							'number' => $product['number'],
							'oos_quantity' => $product_warehouse['sold_quantity'] - $product_warehouse['actual_quantity'],
							'budget_quantity' => 0,
							'actual_quantity' => 0,
							'pending_quantity' => 0
						);
						if ($product_warehouse['purchase_budget_quantity'] < ($product_warehouse['sold_quantity'] - $product_warehouse['actual_quantity']))
						{
							$product_arr[$product_warehouse['product_basic_id']]['budget_quantity'] = ($product_warehouse['sold_quantity'] - $product_warehouse['actual_quantity']) - $product_warehouse['purchase_budget_quantity'];
							$product_arr[$product_warehouse['product_basic_id']]['actual_quantity'] = ($product_warehouse['sold_quantity'] - $product_warehouse['actual_quantity']) - $product_warehouse['purchase_quantity'];
							$product_arr[$product_warehouse['product_basic_id']]['pending_quantity'] = $product_warehouse['purchase_actual_quantity'];
						}
					}
				}
				if ($product_arr)
				{
					$ret[$c['id']] = array(
						'name' => $c['name'],
						'products' => $product_arr
					);
				}
			}
			if (isset($_GET['download']) && $_GET['download'])
			{
				include Q::ini('custom_system/lib_dir').'PHPExcel.php';
				$phpexcel = new PHPExcel();
				$phpexcel->getProperties()->setCreator(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
				$phpexcel->getProperties()->setLastModifiedBy(Q::ini('custom_system/system_name') . Q::ini('custom_system/version'));
				$phpexcel->getProperties()->setTitle("采购汇总表");
				$phpexcel->getProperties()->setSubject("采购汇总表");
				$phpexcel->getProperties()->setDescription("采购汇总表-运营系统");
				$phpexcel->getProperties()->setKeywords("采购汇总表");
				$phpexcel->getProperties()->setCategory("采购汇总表");
				$phpexcel->setActiveSheetIndex(0);
				$phpexcel->getActiveSheet()->setTitle("采购汇总表");
				$phpexcel->getActiveSheet()->setCellValue('A1', "SKU");
				$phpexcel->getActiveSheet()->setCellValue('B1', "产品名称");
				$phpexcel->getActiveSheet()->setCellValue('C1', "所属分类");
				$phpexcel->getActiveSheet()->setCellvalue('D1', '已欠货数量');
				$phpexcel->getActiveSheet()->setCellvalue('E1', '预计采购差');
				$phpexcel->getActiveSheet()->setCellvalue('F1', '实际采购差');
				$phpexcel->getActiveSheet()->setCellValue('G1', "待入库数");
				$phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('B1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('C1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('D1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('E1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('F1')->getFont()->setBold(true);
				$phpexcel->getActiveSheet()->getStyle('G1')->getFont()->setBold(true);
				$i = 2;
				foreach ($ret as $r)
				{
					foreach ($r['products'] as $rp)
					{
						$phpexcel->getActiveSheet()->getCell('A'.$i)->setValueExplicit($rp['number'], PHPExcel_Cell_DataType::TYPE_STRING);
						$phpexcel->getActiveSheet()->setCellValue('B'.$i, $rp['name']);
						$phpexcel->getActiveSheet()->setCellValue('C'.$i, $r['name']);
						$phpexcel->getActiveSheet()->setCellValue('D'.$i, $rp['oos_quantity']);
						$phpexcel->getActiveSheet()->setCellValue('E'.$i, $rp['budget_quantity']);
						$phpexcel->getActiveSheet()->setCellValue('F'.$i, $rp['actual_quantity']);
						$phpexcel->getActiveSheet()->setCellValue('G'.$i, $rp['pending_quantity']);
						$i++;
					}
				}
				$writer = new PHPExcel_Writer_Excel5($phpexcel);
				$file_name = 'PurchaseSummaryReport-' . date('YmdHis', CURRENT_TIMESTAMP) . '-' . CURRENT_USER_NAME . ".xls";
				header("Content-Type: application/vnd.ms-execl");
				header("Content-Type: application/octet-stream");
				header("Content-Type: application/download");
				header('Content-Disposition:inline;filename="'.$file_name.'"');
				header("Content-Transfer-Encoding: binary");
				header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
				header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
				header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
				header("Pragma: no-cache");
				$writer->save('php://output');exit;
			}
			$this->_view['data'] = $ret;
		}
	}
	
	function actionProductNotes()
	{
		$this->_view['title'] = '产品备注';
		$product = Product_basic::find('product_basic.id = ?', $_GET['id'])->asArray()->getOne();
		$this->_view['notes'] = $product['notes'];
	}
	
	function actionSingleNote()
	{
		$this->_view['title'] = '采购备注';
		if ($this->_context->isPOST())
		{
			$err_msg = '';
			if (!empty($_POST['by_note']) && !empty($_POST['purchase_note']))
			{
				foreach (explode(',', $_POST['by_note']) as $n)
				{
					$result = Product_Basic::editNote($n, trim($_POST['purchase_note']), Q::ini('custom_flag/product_basic_purchase_note_flag/single/value'));
					if ($result['ack'] == FAILURE)
					{
						$err_msg .= $result['message'] . "\n"; 
					}
				}
			}
			else
			{
				foreach ($_POST as $k => $v)
				{
					$result = Product_Basic::editNote($k, trim($v['note']), Q::ini('custom_flag/product_basic_purchase_note_flag/single/value'));
					if ($result['ack'] == FAILURE)
					{
						$err_msg .= $result['message'] . "\n"; 
					}
				}
			}
			if ($err_msg)
			{
				return $this->_redirectMessage('备注部分失败', $err_msg, $_SERVER['HTTP_REFERER'], FAILURE);
			}
			else
			{
				return $this->_redirectMessage('备注成功', '正在返回..', $_SERVER['HTTP_REFERER'], SUCCESS);
			}
		}
	}
	
	function actionRepeatNote()
	{
		$this->_view['title'] = '重复备注';
		if ($this->_context->isPOST())
		{
			$err_msg = '';
			if (!empty($_POST['by_note']) && !empty($_POST['purchase_note']))
			{
				foreach (explode(',', $_POST['by_note']) as $n)
				{
					$result = Product_Basic::editNote($n, trim($_POST['purchase_note']), Q::ini('custom_flag/product_basic_purchase_note_flag/repeat/value'));
					if ($result['ack'] == FAILURE)
					{
						$err_msg .= $result['message'] . "\n"; 
					}
				}
			}
			else
			{
				foreach ($_POST as $k => $v)
				{
					$result = Product_Basic::editNote($k, trim($v['note']), Q::ini('custom_flag/product_basic_purchase_note_flag/repeat/value'));
					if ($result['ack'] == FAILURE)
					{
						$err_msg .= $result['message'] . "\n"; 
					}
				}
			}
			if ($err_msg)
			{
				return $this->_redirectMessage('备注部分失败', $err_msg, $_SERVER['HTTP_REFERER'], FAILURE);
			}
			else
			{
				return $this->_redirectMessage('备注成功', '正在返回..', $_SERVER['HTTP_REFERER'], SUCCESS);
			}
		}
	}
}